const program = require('commander');

const {
  createProjectAction,
  createReactProjectAction,
  addComponentAction,
  addReactComponentAction,
  addPageAndRouteAction,
  addStoreAction
} = require('./actions');

const createCommands = () => {
  // command用于制作一个指令，这里制作了一个create的指令，也就是用户输入bin create的指令，<project>是用户输入create后在输入的名字
  program
    .command('create-vue <project> [others...]')
    .description('clone a repository into a folder')
    .action(createProjectAction);

  program
    .command('create-react <project> [others...]')
    .description('clone a repository into a folder')
    .action(createReactProjectAction);

  program
    .command('addvuecpn <name>')
    .description('add vue component, 例如: why addvuecpn HelloWorld [-d src/components]')
    .action((name) => {
      addComponentAction(name, program.dest || 'src/components');
    });

  program
    .command('addreactcpn <name>')
    .description('add react component, 例如: why addreactcpn HelloWorld [-d src/components]')
    .action(name => {
      addReactComponentAction(name,  program.dest || 'src/components');
    });

  program
    .command('addvuepage <page>')
    .description('add vue page and router config, 例如: why addvuepage Home [-d src/pages]')
    .action((page) => {
      addPageAndRouteAction(page, program.dest || 'src/pages')
    })

  program
    .command('addvuestore <store>')
    .description('add vue page and router config, 例如: why addvuestore Home [-d src/pages]')
    .action((store) => {
      addStoreAction(store, program.dest || 'src/store/modules')
    })
}


module.exports = createCommands;
